package com.haoniu.web.controller.module;

import com.haoniu.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.haoniu.common.annotation.Log;
import com.haoniu.common.enums.BusinessType;
import com.haoniu.module.domain.database.UserMoneyDetail;
import com.haoniu.module.service.UserMoneyDetailService;
import com.haoniu.web.core.base.BaseController;
import com.haoniu.framework.web.page.TableDataInfo;
import com.haoniu.common.base.AjaxResult;

import java.util.List;
/**
 * 金额详情流水 信息操作处理
 *
 * @author houyijun
 * @date 2019-01-25
 */
@Controller
@RequestMapping("/module/userMoneyDetail")
public class UserMoneyDetailController extends BaseController
{
    private String prefix = "module/userMoneyDetail";

	@Autowired
	private UserMoneyDetailService userMoneyDetailService;

	@RequiresPermissions("module:userMoneyDetail:view")
	@GetMapping()
	public String userMoneyDetail()
	{
	    return prefix + "/userMoneyDetail";
	}

	/**
	 * 查询金额详情流水列表
	 */
	@RequiresPermissions("module:userMoneyDetail:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(UserMoneyDetail userMoneyDetail) {
		startPage();
        List<UserMoneyDetail> list = userMoneyDetailService.selectUserMoneyDetailList(userMoneyDetail);
		return getDataTable(list);
	}

	/**
	 * 新增金额详情流水
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/add";
	}

	/**
	 * 新增保存金额详情流水
	 */
	@RequiresPermissions("module:userMoneyDetail:add")
	@Log(title = "金额详情流水", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(UserMoneyDetail userMoneyDetail) {
        userMoneyDetail.setCreateBy(ShiroUtils.getLoginName());
		return toAjax(userMoneyDetailService.insertUserMoneyDetail(userMoneyDetail));
	}

	/**
	 * 修改金额详情流水
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
		UserMoneyDetail userMoneyDetail = userMoneyDetailService.selectUserMoneyDetailById(id);
		mmap.put("userMoneyDetail", userMoneyDetail);
	    return prefix + "/edit";
	}

	/**
	 * 修改保存金额详情流水
	 */
	@RequiresPermissions("module:userMoneyDetail:edit")
	@Log(title = "金额详情流水", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(UserMoneyDetail userMoneyDetail) {
        userMoneyDetail.setUpdateBy(ShiroUtils.getLoginName());
		return toAjax(userMoneyDetailService.updateUserMoneyDetail(userMoneyDetail));
	}

	/**
	 * 删除金额详情流水
	 */
	@RequiresPermissions("module:userMoneyDetail:remove")
	@Log(title = "金额详情流水", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(userMoneyDetailService.deleteUserMoneyDetailByIds(ids));
	}

}
